package com.qf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.annotation.IsLogin;
import com.qf.entity.Collect;
import com.qf.entity.R;
import com.qf.entity.User;
import com.qf.service.CollectService;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * (Collect)表控制层
 *
 * @author makejava
 * @since 2020-10-05 18:41:04
 */
@RestController
@RequestMapping("/user")
public class CollectController{
    /**
     * 服务对象
     */
    @Autowired
    private CollectService collectService;

    @RequestMapping("/addCollect")
    @IsLogin(mustLogin = true)
    public R<Boolean> addCollect(Integer userId, Integer hid, String ActionType){
        //根据用户所浏览的酒店id查找collect中的code状态
        Collect collect = collectService.getOne(new QueryWrapper<Collect>().eq("hid", hid));

        if (ActionType.equals("CX")){
            if (collect.getCode() == 0){
                System.out.println("加载状态为0时：" + collect);
                return new R<Boolean>().setCode(R.Code.SUCCESS).setData(true);
            }else{
                System.out.println("加载状态为1时：" + collect);
                return new R<Boolean>().setCode(R.Code.ERROR).setData(true);
            }
        }
        if (ActionType == ""){
            if (collect.getCode() == 0){
                collect.setCode(1);
                collectService.saveOrUpdate(collect);
                System.out.println("点击状态为0时：" + collect);
                return new R<Boolean>().setCode(R.Code.ERROR).setData(true);
            }else {
                collect.setCode(0);
                collectService.saveOrUpdate(collect);
                System.out.println("点击状态为1时：" + collect);
                return new R<Boolean>().setCode(R.Code.SUCCESS).setData(true);
            }
        }
        return new R<Boolean>().setData(true);
    }
}